<template>
	<view class="parent-view">
		<view class="date-parent">
			<text class="date-ri-txt">{{day}}</text>
			<text class="date-zhou-txt">{{today}}</text>
			<text class="date-zhong-nian-txt">{{nongliDay}}</text>
		</view>
		<view class="memorial-list">
			<view class="memorial-item" v-for="(item , index) in memList" :key="'mem_'+index"
				 @click="memItemClick" :data-index="item">
				<image class="mem-head" :src="item.avatar"></image>
				<view class="mem-content">
					<text class="mem-item-name">{{item.name+item.title}}</text>
					<text class="mem-item-date">{{item.riqi}}</text>
				</view>
				<view class="mem-leftday">
					<text class="leftday-num" v-if="item.surplus==0">今天</text>
					<view style="display: flex;flex-direction: column;" v-else>
						<text class="leftday-txt" >还有</text>
						<text class="leftday-num" v-if="item.surplus!==0&&item.surplus=='未知'">0天</text>
						<text class="leftday-num" v-if="item.surplus!==0&&item.surplus!=='未知'">{{item.surplus}}天</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import request from '../index/request.js';
	import {getLunar} from 'chinese-lunar-calendar'
	export default {
		data() {
			return {
				memList:null,
				day:"",
				today:"",
				nongliDay:"",
				weeks:["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
				treeId:"",
				treeTitle:"",
			}
		},
		methods: {
			onLoad:function(options){
				this.appUtil.saveAppInviteId(options)
				this.treeId=options.id
				this.treeTitle=options.title
				uni.setNavigationBarTitle({
					title:this.treeTitle+"《纪念日》"
				})
				this.getTime()
			},
			onShow:function(){
				this.GetTreeCommemorationRi()
				this.share.url='/pages/tabBar/home/index?appInviteId='+this.appUtil.getAppInviteId()
				this.share.shareType=1
			},
			getTime:function(){
				var date = new Date()
				var year = date.getFullYear()
				var month = date.getMonth() + 1
				this.day = date.getDate()
				this.today=year+"年"+month+"月"+this.day+"日"+"  "+this.weeks[date.getDay()]
				var nongli=getLunar(year, month, this.day)
				this.nongliDay=nongli.lunarYear+"  "+nongli.dateStr
			},
			GetTreeCommemorationRi:function(){
				var that=this
				request.post("api/user/GetTreeCommemorationRi",{
					Treeid:this.treeId
				}).then(data=>{
					that.memList=data.datas
				})
			},
			memItemClick:function(event){
				let item = event.currentTarget.dataset.index;
				uni.navigateTo({
					url:"/pages/tree-card-info/index?cardId="+item.id
				})
			},
		}
	}
</script>

<style>
	@import "index.css";
</style>
